package com.example.newnoke.fragment.main;

import android.databinding.DataBindingUtil;
import android.view.View;

import com.example.newnoke.R;
import com.example.newnoke.adapter.CommonAdapter;
import com.example.newnoke.adapter.ViewHolder;
import com.example.newnoke.data.IconData;
import com.example.newnoke.databinding.FragmentHomeBinding;
import com.example.newnoke.mvp.presenter.TestPresenter;
import com.example.newnoke.mvp.view.ITestV;
import com.example.newnoke.utils.GlideImageLoader;
import com.geya.jbase.basefragment.BaseDetailsFragment;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2018/5/22 0022.
 */

public class HomeFragment extends BaseDetailsFragment<TestPresenter> implements ITestV {

    private FragmentHomeBinding mBinding;

    @Override
    public TestPresenter newPresenter() {
        return new TestPresenter(this);
    }

    @Override
    public int inflateCreateView() {
        return R.layout.fragment_home;
    }

    @Override
    public void initDatas(View view) {
        mBinding = DataBindingUtil.bind(view);
        List<String> list = new ArrayList<>();
        list.add("http://e.hiphotos.baidu.com/image/pic/item/72f082025aafa40fafb5fbc1a664034f78f019be.jpg");
        list.add("http://c.hiphotos.baidu.com/image/pic/item/38dbb6fd5266d016c364ad369a2bd40735fa35aa.jpg");
        list.add("http://a.hiphotos.baidu.com/image/pic/item/b2de9c82d158ccbfc471743b14d8bc3eb03541e6.jpg");
        list.add("http://e.hiphotos.baidu.com/image/pic/item/e7cd7b899e510fb3339fdf89d433c895d1430c2d.jpg");
        setBanner(list);
        initIconButton();

    }

    public void setBanner(final List<String> imgs) {

        if (imgs.size()>0) {
            mBinding.banner.setImages(imgs).setImageLoader(new GlideImageLoader()).setOnBannerListener(new OnBannerListener() {
                @Override
                public void OnBannerClick(int position) {


                }
            }).start();
        }

    }


    private CommonAdapter<IconData> mAdapter;
    private CommonAdapter<IconData> mAdapter2;

    public void initIconButton(){

        List<IconData> list2 = new ArrayList<>();
        list2.add(new IconData( R.mipmap.ic_launcher_round,"淘宝"));
        list2.add(new IconData( R.mipmap.ic_launcher_round,"淘宝"));
        list2.add(new IconData( R.mipmap.ic_launcher_round,"淘宝"));
        list2.add(new IconData( R.mipmap.ic_launcher_round,"淘宝"));
        list2.add(new IconData( R.mipmap.ic_launcher_round,"淘宝"));
        list2.add(new IconData( R.mipmap.ic_launcher_round,"淘宝"));
        list2.add(new IconData( R.mipmap.ic_launcher_round,"淘宝"));
        list2.add(new IconData( R.mipmap.ic_launcher_round,"淘宝"));
        list2.add(new IconData( R.mipmap.ic_launcher_round,"淘宝"));
        list2.add(new IconData( R.mipmap.ic_launcher_round,"淘宝"));


        mAdapter = new CommonAdapter<IconData>(getContext(),list2,R.layout.item_icon) {
            @Override
            public void convert(ViewHolder holder, IconData iconData, int position) {
                holder.setImgeSrc(R.id.img,iconData.getIcon())
                        .setText(R.id.name,iconData.getName());
            }
        };

        mBinding.homeGridview.setAdapter(mAdapter);


        mAdapter2 = new CommonAdapter<IconData>(getContext(),list2,R.layout.item_home_list) {
            @Override
            public void convert(ViewHolder holder, IconData iconData, int position) {

            }
        };

        mBinding.gridview.setAdapter(mAdapter2);

    }


}
